#include <stdio.h>
int main()
{
	typedef struct
	{
		char num[200];
		int score;
		int eng;
	}student;
	student a[200] ={{0},0,0};
	int m,n;
	scanf("%d %d",&m,&n);
	for(int i=0;i < m;i++)
	{
		scanf("%s %d %d",&a[i].num,&a[i].score,&a[i].eng);
	}
	
	for(int i = 0;i < m-1;i++)
	{
		int flag = 0;
		for(int j = 0;j <m-i-1;j++)
		{
			if((a[j].score < a[j+1].score)||(a[j].score==a[j+1].score&&a[j].eng < a[j+1].eng)||(a[j].score==a[j+1].score&&a[j].eng == a[j+1].eng&&a[j].num>a[j+1].num))
			{
				student t = a[j];
				a[j] =a[j+1];
				a[j+1] = t;
				flag = 1;
			}
		}
		if(flag==0) break;
	}
	for(int i = 0;i < n;i++)
	{
		printf("%s %d %d\n",a[i].num,a[i].score,a[i].eng);
	}
	return 0;
	
}